//
//  UserResumeContentViewController.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/8/14.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "UserResumeContentViewController.h"
#import "XHImageUrlViewer.h"

@interface UserResumeContentViewController (){
    UIScrollView *scrollBG;
    NSDictionary *dicAllData;
    NSMutableArray *imagebig;
    XHImageUrlViewer *imgView;
}

@end

@implementation UserResumeContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    imagebig=[NSMutableArray new];
    
    scrollBG=[[UIScrollView alloc] initWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kContentHeight)];
    scrollBG.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:scrollBG];
    scrollBG.autoresizingMask=UIViewAutoresizingFlexibleHeight;
    
    [self loadData];
    
}
-(void)loadData{
    krequestParam
    [dictparam setValue:[self.otherInfo valueForJSONStrKey:@"id"] forKey:@"id"];
    [NetEngine createPostAction:XKFV4customerarchives withParams:dictparam onCompletion:^(id resData, BOOL isCache) {
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            dicAllData=[resData objectForJSONKey:@"data"];
            [self loadContentView];
        }else{
            [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [super backButtonClicked:nil];
            });
        }
    } onError:^(NSError *error) {
        [SVProgressHUD showImage:nil status:alertErrorTxt];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [super backButtonClicked:nil];
        });
    }];
}
-(void)loadContentView{
    float fty=10;
    UIImageView *iamgeV=[RHMethods imageviewWithFrame:CGRectMake(10, fty, 40, 40) defaultimage:@"loadImageBG" ];
    [[Utility Share] viewLayerRound:iamgeV borderWidth:0.1 borderColor:[UIColor clearColor]];
    [scrollBG addSubview:iamgeV];
    [iamgeV imageWithURL:[dicAllData valueForJSONStrKey:@"path"] useProgress:NO useActivity:NO];
    UILabel *lblDate=[RHMethods labelWithFrame:CGRectMake(60, fty, 0, 20) font:fontSmallTitle color:rgbTxtDeepGray text:[dicAllData valueForJSONStrKey:@"ctime"]];
    [scrollBG addSubview:lblDate];
    lblDate.frameX=kScreenWidth-10-W(lblDate);
    UILabel *lblName=[RHMethods labelWithFrame:CGRectMake(60, fty, X(lblDate)-60, 20) font:fontTitle color:rgbTitleColor text:[dicAllData valueForJSONStrKey:@"name"]];
    [scrollBG addSubview: lblName];
    fty+=20;
    [scrollBG addSubview:[RHMethods labelWithFrame:CGRectMake(X(lblName), fty, kScreenWidth-X(lblName)-10, 20) font:fontTxtContent color:rgbTxtDeepGray text:[NSString stringWithFormat:@"%@  %@",[dicAllData valueForJSONStrKey:@"job"],[dicAllData valueForJSONStrKey:@"companyname"]]]];
    fty+=20;
    [scrollBG addSubview:[RHMethods labelWithFrame:CGRectMake(X(lblName), fty, kScreenWidth-X(lblName)-10, 20) font:fontTxtContent color:rgbpublicColor text:[NSString stringWithFormat:@"%@年  %@  %@  工号：%@",[dicAllData valueForJSONStrKey:@"worktime"],[dicAllData valueForJSONStrKey:@"education"],[dicAllData valueForJSONStrKey:@"department"],[dicAllData valueForJSONStrKey:@"jobnum"]]]];
    fty+=26;
    UILabel *lblContent=[RHMethods labelWithFrame:CGRectMake(10, fty, kScreenWidth-20, 0) font:fontTxtContent color:rgbTitleDeepGray text:[dicAllData valueForJSONStrKey:@"descr"] textAlignment:NSTextAlignmentLeft setLineSpacing:4];
    [scrollBG addSubview:lblContent];
    fty+=H(lblContent)+10;
    UIView *viewLineG=[RHMethods lineViewWithFrame:CGRectMake(0, fty, kScreenWidth, 10)];
    [viewLineG setBackgroundColor:rgbGray];
    [scrollBG addSubview:viewLineG];
    fty+=10;
    [scrollBG addSubview:[RHMethods labelWithFrame:CGRectMake(10, fty, 0, 30) font:fontTitle color:rgbTitleDeepGray text:@"轨迹"]];
    fty+=30;
    [scrollBG addSubview:[RHMethods lineViewWithFrame:CGRectMake(10, fty, kScreenWidth-20, 0.5)]];
    fty+=10;
    UIView *viewLine=[RHMethods lineViewWithFrame:CGRectMake(25, fty, 0.5, 100)];
    [scrollBG addSubview:viewLine];
    float ftx=40;
    [imagebig removeAllObjects];
    for (NSDictionary *dic in [dicAllData objectForJSONKey:@"trajectoy"]) {
        UIView *viewD=[[UIView alloc] initWithFrame:CGRectMake(21.25, fty, 8, 8)];
        viewD.backgroundColor=rgbpublicColor;
        [[Utility Share] viewLayerRound:viewD borderWidth:0.1 borderColor:rgbpublicColor];
        [scrollBG addSubview:viewD];
        
        [scrollBG addSubview:[RHMethods labelWithFrame:CGRectMake(ftx, fty, kScreenWidth-ftx-10, 20) font:fontTitle color:rgbTitleColor text:[dic valueForJSONStrKey:@"tratime"]]];
        fty+=20;
        UILabel *lblC= [RHMethods labelWithFrame:CGRectMake(ftx, fty, kScreenWidth-ftx-10, 0) font:fontTxtContent color:rgbTxtDeepGray text:[dic valueForJSONStrKey:@"descr"] textAlignment:NSTextAlignmentLeft setLineSpacing:4];
        [scrollBG addSubview:lblC];
        fty+=H(lblC)+10;
        
        NSArray *arrarImage=[dic valueForJSONKey:@"src"];
        if ([arrarImage count]) {
            float ftempW=75.0*kScreenWidth/320.0;
            float ftempX=ftx;
            for (int i=0; i<[arrarImage count]; i++) {
                if (i!=0 && i%3==0) {
                    ftempX=ftx;
                    fty+=ftempW+5;
                }
                NSDictionary *dTemp=[arrarImage objectAtIndex:i];
                UIImageView *imageV=[RHMethods imageviewWithFrame:CGRectMake(ftempX, fty, ftempW, ftempW) defaultimage:@"loadImageBG"];
                [imageV imageWithURL:[dTemp valueForJSONStrKey:@"middle_path"] useProgress:NO useActivity:NO];
                imageV.userInteractionEnabled=YES;
                [scrollBG addSubview:imageV];
                [imageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClicked:)]];
                imageV.tag=[imagebig count];
                
                [imagebig addObject:@{@"cacheUrl":[dTemp valueForJSONStrKey:@"middle_path"],@"url":[dTemp valueForJSONStrKey:@"path"]}];
                ftempX+=ftempW+5;
            }
            fty+=ftempW+10;
        }
        
    }
    viewLine.frameHeight=fty-Y(viewLine);
    
    [scrollBG setContentSize:CGSizeMake(kScreenWidth, fty>H(scrollBG)+1?fty:H(scrollBG)+1)];
    
}
#pragma mark clicked
-(void)imageClicked:(UITapGestureRecognizer *)tap{
    if (!imgView ) {
        imgView=[[XHImageUrlViewer alloc] init];
    }
    [imgView showWithImageDatas:imagebig selectedIndex:tap.view.tag];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
